<!DOCTYPE html>
<html>
<head>
    <title>
        首页
    </title>
    <link href="/static/base.css" rel="stylesheet" type="text/css">
    </link>
    <script src="/static/jquery3.4.js">
    </script>
    <script src="/static/jqueryCookie1.4.1.js">
    </script>
    <script src="/static/lib.js">
    </script>
</head>
<style type="text/css">
    h1 {
        text-align: center;
    }

    .div1 {

    }

    .info {
        display: none;
        text-align: center;
    }

    .info a {
        margin-left: 10px;
        color: white;
    }

    .username {

    }
    #avator{
        height: 4rem;
    }
</style>
<body>
<h1 onclick="javascript:location.href='/'">
    首页
</h1>
<div class="div1">
    <div class="info unlogin">
        <a href="/loginpage">
            请登录...
        </a>
        <a href="/registepage">
            注册
        </a>
    </div>
    <div class="info login">
                <span>
                    你好!
                    <span class="username">
                    </span>
                    ~
                </span>
        <img src="" alt="头像" id="avator">
        <a href="/editpage">
            编辑
        </a>
        <a href="javascript:void(0)" id="logout">
            退出
        </a>
    </div>
</div>

</body>

</html>
<script type="text/javascript">
    $(function () {
        canvas();
        user = getUser()
        if (user) {
            $('.username').html(user.user_name);
            $('#avator').attr('src', "/img/"+user.user_avator);
            $('.login').show();
            $('.unlogin').hide();
            $('#logout').on('click', function () {
                $.ajax({
                    url: '/logout',
                    data: {token: localStorage.getItem("token")},
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 200) {
                            localStorage.removeItem("token")
                            location.href = '/loginpage'
                        } else {
                            alert(res.msg)
                        }
                    }
                });
            })
        } else {
            $('.login').hide();
            $('.unlogin').show();
        }
    });
</script>